import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-12-20
 * Time:20:49
 */
 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int m=in.nextInt();
        int n=in.nextInt();
        int min=mins(m,n);
        System.out.println(m*n/min);
    }
    public static int mins(int m,int n){
        if(m==n){
            return m;
        }
        if(m<n){
            int tmp=m;
            m=n;
            n=tmp;
        }
        while(m%n!=0){
            int tmp=m%n;
            m=n;
            n=tmp;
        }
        return n;
    }
}
public class Test {
    public static void main(String[] args) throws IOException {
//        Scanner scanner=new Scanner(System.in);
//        int n= scanner.nextInt();
//        String []strings=new String[n];
//        for (int i = 0; i < n; i++) {
//            strings[i]= scanner.nextLine();
//        }
        BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
        int n= Integer.parseInt(read.readLine());
        String[] strings=new String[n];
        for (int i = 0; i < strings.length; i++) {
            strings[i]= read.readLine();
        }
        if(isSortZidian(strings)&&isSortLength(strings)){
            System.out.println("both");
        }else if(isSortZidian(strings)){
            System.out.println("lexicographically");
        }else if(isSortLength(strings)){
            System.out.println("lengths");
        }else{
            System.out.println("none");
        }
    }

    private static boolean isSortZidian(String[] strings) {
        for (int i = 0; i < strings.length; i++) {
            if(strings[i].compareTo(strings[i+1])>0){
                return false;
            }
        }
        return true;
    }

    private static boolean isSortLength(String[] strings) {
        for (int i = 0; i < strings.length; i++) {
            if(strings[i].length()>strings[i+1].length()){
                return false;
            }
        }
        return true;
    }
}
